package com.bhs.sansonglogistics.ui.mine;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.util.ArrayMap;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.base.BaseActivity;
import com.bhs.sansonglogistics.bean.BehaviorBean;
import com.bhs.sansonglogistics.bean.BillDataBean;
import com.bhs.sansonglogistics.bean.BillingDetails;
import com.bhs.sansonglogistics.net.Config;
import com.bhs.sansonglogistics.net.NetCallBack;
import com.bhs.sansonglogistics.ui.adapter.BillAdapter;
import com.bhs.sansonglogistics.ui.adapter.LooseChangeAdapter;
import com.bhs.sansonglogistics.ui.other.WebViewActivity;
import com.bhs.sansonglogistics.utils.LogUtils;
import com.bhs.sansonglogistics.utils.MyUtils;
import com.bhs.sansonglogistics.utils.StatusBarUtil;
import com.bhs.sansonglogistics.utils.ToastUtil;
import com.bhs.sansonglogistics.view.ArcProgressBar;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.Gson;

import java.util.Map;
import java.util.Random;

import okhttp3.ResponseBody;
import retrofit2.Response;

/**
 * 行为分
 */
public class BehaviorActivity extends BaseActivity implements View.OnClickListener, NetCallBack {

    //BehaviorBean
    private RecyclerView mRvList;
    private LooseChangeAdapter mAdapter;
    private ArcProgressBar mArcProgressBar;
    private TextView mTvCreditScore;
    private TextView mTvGrade;
    private TextView mTvInfluence;
    private TextView mTvManifestation;


    @Override
    public int initLayout() {
        return R.layout.activity_behavior;
    }

    @Override
    public void initView() {
        StatusBarUtil.setTranslucentStatus(this, true);
        if (!StatusBarUtil.setStatusBarDarkTheme(this, true)) {
            StatusBarUtil.setStatusBarColor(this, 0x55000000);
        }
        findViewById(R.id.tv_rule).setOnClickListener(this);
        mRvList = findViewById(R.id.rv_list);
        mArcProgressBar = findViewById(R.id.arcProgressBar);
        findViewById(R.id.tv_rule).setOnClickListener(this);
        mTvCreditScore = findViewById(R.id.tv_credit_score);
        mTvGrade = findViewById(R.id.tv_grade);
        findViewById(R.id.tv_record).setOnClickListener(this);
        mTvInfluence = findViewById(R.id.tv_Influence);
        mTvManifestation = findViewById(R.id.tv_manifestation);

    }

    @SuppressLint("InflateParams")
    @Override
    public void initData() {
        String behavior = getIntent().getStringExtra("Behavior");
        mArcProgressBar.setProgressBar(Float.parseFloat(behavior) < 40 ? 40 : Float.parseFloat(behavior));
        mTvCreditScore.setText(behavior);
        mTvGrade.setText(MyUtils.getGrade(Float.parseFloat(behavior)));
        mTvInfluence.setText(String.format("相应权益：%s", MyUtils.getInfluence(Float.parseFloat(behavior))));
        mAdapter = new LooseChangeAdapter(1);
        mRvList.setAdapter(mAdapter);
        mRvList.setLayoutManager(new LinearLayoutManager(this));
        mAdapter.setEmptyView(LayoutInflater.from(this).inflate(R.layout.layout_empty, null));
        mTvManifestation.setText(String.format("您当前表现%s", MyUtils.getGrade(Float.parseFloat(behavior))));
        loadData();
    }

    private void loadData() {
        Map<String, String> map = new ArrayMap<>();
        map.put("page", "1");
        map.put("limit", "10");
        map.put("wallet_type", "money03");
        map.put("data_type", "1");
        map.put("platform", "logistics");
        networkRequest(netApi.get_wallet_log(map), this);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.tv_rule) {
            String url = "file:///android_asset/index.html";
            startActivity(new Intent(new Intent(mActivity, WebViewActivity.class))
                    .putExtra("url", url)
                    .putExtra("title", "规则"));
        } else if (view.getId() == R.id.tv_record) {
            startActivity(new Intent(mActivity, BehaviorRecordActivity.class));
        }
    }

    @Override
    public void onResponse(int requestCode, String json, Response<ResponseBody> response) throws Exception {
        BillDataBean bean = new Gson().fromJson(json, BillDataBean.class);
        if (bean.isStatus()) {
            mAdapter.setNewData(bean.getData().getList());
        } else {
            ToastUtil.show(bean.getMsg());
        }
    }

    @Override
    public void onFailure(int requestCode) {

    }
}